HAL MMC peripheral control functions

This section provides information about the HAL MMC peripheral control functions migration.

HAL MMC card initialization

Note

  • In HAL1, HAL_MMC_InitCard() can be invoked by the application to reinitialize the card after a plug-off/plug-in event.

  • In HAL2, HAL_MMC_NotifyCardInsertion() can be used in the event of hot plug-in.

  • Additionally, HAL2 provides HAL_MMC_NotifyCardRemoval() to set default SDMMC configurations upon card plug-off.

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_InitCard(MMC_HandleTypeDef *hmmc)

Removed; usage sequence changed, see below note for details.

Note

  • In HAL1, HAL_MMC_InitCard() can be invoked by the application to reinitialize the card after a hot plug-off/plug-in event.

  • HAL2 provides HAL_MMC_NotifyCardRemoval() to set default configurations upon card plug-off. Then, application code should invoke HAL_MMC_NotifyCardInsertion() at card insertion.

  • Refer to Hot plug-in / Hot plug-off use case for more details on hot plug handling in HAL2.


HAL MMC RPMB management

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_RPMB_ProgramAuthenticationKey(MMC_HandleTypeDef *hmmc,
                                                        const uint8_t *pKey,
                                                        uint32_t Timeout)
hal_status_t HAL_MMC_ProgramRPMBAuthenticationKey(hal_mmc_handle_t *hmmc,
                                                  const uint8_t *p_key,
                                                  uint32_t timeout_ms)
uint32_t HAL_MMC_RPMB_GetWriteCounter(MMC_HandleTypeDef *hmmc,
                                      uint8_t *pNonce,
                                      uint32_t Timeout)
hal_status_t HAL_MMC_GetRPMBWriteCounter(hal_mmc_handle_t *hmmc,
                                         uint8_t *p_nonce,
                                         uint32_t *p_write_counter,
                                         uint32_t timeout_ms)

Note

  • In HAL1, the write counter was returned via the function return value.

  • In HAL2, the write counter is returned via an output parameter.


HAL MMC partition selection

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_SwitchPartition(MMC_HandleTypeDef *hmmc,
                               HAL_MMC_PartitionTypeDef partition)
hal_status_t HAL_MMC_SelectPartitionArea(hal_mmc_handle_t *hmmc,
                        hal_mmc_area_partition_t area_partition)

HAL MMC configure wide bus operation

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation(MMC_HandleTypeDef *hmmc,
                                                 uint32_t WideMode)

Removed; To configure the bus width, set the appropriate field in the hal_mmc_config_t structure and call HAL_MMC_SetConfig().

Example code snippet

HAL1

HAL2

hmmc_card.Init.ClockEdge           = SDMMC_CLOCK_EDGE_RISING;
hmmc_card.Init.ClockPowerSave      = SDMMC_CLOCK_POWER_SAVE_DISABLE;
hmmc_card.Init.BusWide             = SDMMC_BUS_WIDE_1B;
hmmc_card.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_ENABLE;
hmmc_card.Init.ClockDiv            = SDMMC_HSPEED_CLK_DIV;

hmmc_card.Instance = SDMMC;
HAL_MMC_Init(&hmmc_card);

HAL_MMC_ConfigWideBusOperation(&hmmc_card, SDMMC_BUS_WIDE_4B);
HAL_MMC_Init(&hmmc_card, SDMMC);
HAL_MMC_MspInit(&hmmc_card);

config.clk_cfg.clk_edge       = HAL_MMC_CLOCK_EDGE_RISING;
config.clk_cfg.clk_power_save = HAL_MMC_CLOCK_POWER_SAVE_DISABLE;
config.bus_wide               = HAL_MMC_BUS_WIDE_4BIT;
config.hw_flow_ctrl           = HAL_MMC_HARDWARE_FLOW_CONTROL_ENABLE;
config.data_timeout_cycle     = HAL_MMC_DATA_MAX_TIMEOUT;
config.erase_timeout_ms       = HAL_MMC_ERASE_MAX_TIMEOUT;
config.stop_xfer_timeout_ms   = HAL_MMC_STOP_XFER_MAX_TIMEOUT;

HAL_MMC_SetConfig(&hmmc_card, &config);

HAL MMC configure speed bus operation

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_ConfigSpeedBusOperation(MMC_HandleTypeDef *hmmc,
                                                  uint32_t SpeedMode)
hal_status_t HAL_MMC_SwitchSpeedMode(hal_mmc_handle_t *hmmc,
                            hal_mmc_speed_mode_t speed_mode)

Note

In HAL1, the speed mode selection parameter had used values defined in the SDMMC core driver ( sdmmc_core.h). In HAL2, use the provided enumeration hal_mmc_speed_mode_t for speed modes.


HAL MMC device power state

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_SleepDevice(MMC_HandleTypeDef *hmmc)
hal_status_t HAL_MMC_EnterCardSleepMode(hal_mmc_handle_t *hmmc)
HAL_StatusTypeDef HAL_MMC_AwakeDevice(MMC_HandleTypeDef *hmmc)
hal_status_t HAL_MMC_ExitCardSleepMode(hal_mmc_handle_t *hmmc)

HAL MMC peripheral erase management

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_Erase(MMC_HandleTypeDef *hmmc,
                                uint32_t BlockStartAdd,
                                uint32_t BlockEndAdd)
hal_status_t HAL_MMC_Erase(hal_mmc_handle_t *hmmc,
                           uint32_t start_block_addr,
                           uint32_t end_block_addr)
HAL_StatusTypeDef HAL_MMC_EraseSequence(MMC_HandleTypeDef *hmmc,
                                        uint32_t EraseType,
                                        uint32_t BlockStartAdd,
                                        uint32_t BlockEndAdd)
hal_status_t HAL_MMC_EraseSequence(hal_mmc_handle_t *hmmc,
                                   hal_mmc_erase_type_t erase_type,
                                   uint32_t start_block_addr,
                                   uint32_t end_block_addr)
HAL_StatusTypeDef HAL_MMC_Sanitize(MMC_HandleTypeDef *hmmc)
hal_status_t HAL_MMC_Sanitize(hal_mmc_handle_t *hmmc)

HAL MMC secure removal type

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_ConfigSecRemovalType(MMC_HandleTypeDef *hmmc,
                                               uint32_t SRTMode)
hal_status_t HAL_MMC_SetSecureRemovalType(hal_mmc_handle_t *hmmc,
                                          hal_mmc_secure_removal_type_t sec_removal_type)
HAL_StatusTypeDef HAL_MMC_GetSupportedSecRemovalType(MMC_HandleTypeDef *hmmc,
                                                     uint32_t *SupportedSRT)
hal_mmc_secure_removal_type_t HAL_MMC_GetSecureRemovalType(const hal_mmc_handle_t *hmmc)

Note

  • In HAL1, the function used an output parameter to return the secure removal type.

  • In HAL2, the function directly returns the secure removal type.


HAL MMC card information

HAL1

HAL2

HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc)
hal_mmc_card_state_t HAL_MMC_GetCardState(const hal_mmc_handle_t *hmmc)

HAL MMC get card CID

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_GetCardCID(const MMC_HandleTypeDef *hmmc,
                         HAL_MMC_CardCIDTypeDef *pCID)
void HAL_MMC_GetCardCID(const hal_mmc_handle_t *hmmc,
                hal_mmc_card_cid_t *p_cid)

HAL MMC get card info

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_GetCardInfo(const MMC_HandleTypeDef *hmmc,
                                 HAL_MMC_CardInfoTypeDef *pCardInfo)
void HAL_MMC_GetCardInfo(const hal_mmc_handle_t *hmmc,
                     hal_mmc_card_info_t *p_card_info)

HAL MMC get card CSD

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_GetCardCSD(MMC_HandleTypeDef *hmmc,
                                HAL_MMC_CardCSDTypeDef *pCSD)

Removed; HAL2 parses CSD register internally, the function and related structure are removed.


HAL MMC get card EXT_CSD

HAL1

HAL2

HAL_StatusTypeDef HAL_MMC_GetCardExtCSD(MMC_HandleTypeDef *hmmc,
                                        uint32_t *pExtCSD,
                                        uint32_t Timeout)

Removed; HAL2 parses Extended CSD register internally, the function and related structure are removed.